package baseFx.log;

public enum Level {
    ERROR, WARN, INFO, DEBUG, TRACE;

    org.apache.logging.log4j.Level toLog4j() {
        switch (this) {
            case ERROR:
                return org.apache.logging.log4j.Level.ERROR;
            case WARN:
                return org.apache.logging.log4j.Level.WARN;
            case INFO:
                return org.apache.logging.log4j.Level.INFO;
            case DEBUG:
                return org.apache.logging.log4j.Level.DEBUG;
            case TRACE:
                return org.apache.logging.log4j.Level.TRACE;
            default:
                throw new RuntimeException("不支持：" + name());
        }
    }

    static Level fromLog4j(org.apache.logging.log4j.Level level) {
        if (level == org.apache.logging.log4j.Level.WARN) {
            return WARN;
        }
        if (level == org.apache.logging.log4j.Level.INFO) {
            return INFO;
        }
        if (level == org.apache.logging.log4j.Level.DEBUG) {
            return DEBUG;
        }
        if (level == org.apache.logging.log4j.Level.TRACE) {
            return TRACE;
        }
        return ERROR;
    }
}
